<template>
	<view class="content">
		
		<view class="title">{{data.title}}</view>
		<view class="lessTitle" v-show="data.lessTitle">{{data.lessTitle}}</view>
		<view class="item" @tap='KeyboarOpen'>
		  <password-input :numLng='data.password'></password-input>
		</view>
		<number-keyboard tabBar ref='KeyboarHid' @input='onInput' psdLength='6'></number-keyboard>
		
		
	</view>
</template>
<style>
	.content{width: 90%;margin-left: 5%;}
	.content .title{color:#30313B;font-size: 44upx;font-weight: bold;margin-top: 40upx;}
	.content .lessTitle{color:#999999;font-size: 28upx;margin-top: 20upx;}
	.content .item{margin-top: 60upx;}
</style>
<script>
	import numberKeyboard from '@/components/number-keyboard/number-keyboard.vue'
	import passwordInput from '@/components/password-input/password-input.vue'
	import Share from '@/common/wx_share.js'
	export default {
		components: {
			numberKeyboard,
			passwordInput
		},
		data() {
			return {
				share:{
					title:"",
					path:'/pages/tabbar/index',
					imageUrl:'',
					desc:'',
					content:''
				},
				data:{
					title:"请输入支付密码",
					lessTitle:"",
					oldPw:"",
					password:"",
					surePws:"",
					newPw:false,
					surePwsAgain:false,
					again:false
				},

				
			}
		},
		onLoad(){
			setTimeout(() => {
			  this.$refs.KeyboarHid.open()
			}, 50)
			uni.setNavigationBarTitle({title: '身份验证'});
			// this.AjaxLoad()
		},
		methods: {
			AjaxLoad(){
				console.log( this.data )
				return;
				this.data.surePws = "111111"
				let param={
					token:this._$userToken("userInfo").token,
					old_pwd:this.pages
				};
				this._$InitRequest.request("Index/index", param).then(res => {
					console.log( res , "index" );
				},error=>{})
			},
			KeyboarOpen(e) {this.$refs.KeyboarHid.open();},
			onInput(val) {
				this.data.password = val;
				if( this.data.newPw == false ){
					if( this.data.password.length == 6 ){
						let param={
							token:this._$userToken("userInfo").token,
							old_pwd:this.data.password 
						};
						this._$InitRequest.request("MemberInfo/yz_paypwd", param).then(res => {
							uni.showToast({title:res.mess,icon:"none"})
							if( res.status == 200 ){
								this.data.oldPw = this.data.password
								this.data.password = ""
								this.data.title = "请设置新密码，用于支付验证"
								this.data.lessTitle = "请输入新密码"
								uni.setNavigationBarTitle({title: '新支付密码'});
								uni.showToast({title:'验证成功',icon:"none"})
								this.$refs.KeyboarHid.reset()
								this.data.newPw = true
								this.data.surePws = ""
							}
						},error=>{})
					}
					// if( this.data.password.length == 6 && this.data.password !== this.data.surePws ){
					// 	this.data.password = ""
					// 	uni.showToast({title:'密码错误',icon:"none"})
					// 	this.$refs.KeyboarHid.reset()
					// }else if( this.data.password.length == 6 && this.data.password == this.data.surePws ){
					// 	this.data.password = ""
					// 	this.data.title = "请设置新密码，用于支付验证"
					// 	this.data.lessTitle = "请输入新密码"
					// 	uni.setNavigationBarTitle({title: '新支付密码'});
					// 	uni.showToast({title:'验证成功',icon:"none"})
					// 	this.$refs.KeyboarHid.reset()
					// 	this.data.newPw = true
					// 	this.data.surePws = ""
					// }
				}else{
					if( this.data.surePwsAgain == false ){
						if(  this.data.password.length == 6 ){
							this.data.surePws = this.data.password
							this.data.password = ""
							uni.showToast({title:'请再次输入密码',icon:"none"})
							this.$refs.KeyboarHid.reset()
							this.data.surePwsAgain = true
							return;
						}
					}else{
						if( this.data.password.length == 6 && this.data.password !== this.data.surePws ){
							this.data.password = ""
							this.$refs.KeyboarHid.reset()
							this.data.surePwsAgain = false
							uni.showToast({title:'密码和上次不符，请重新输入',icon:"none"})
						}else{
							if( this.data.again == false ){
								this.data.again = true
							}else{
								if( this.data.password.length == 6 && this.data.password == this.data.surePws ){
									let params={
										token:this._$userToken("userInfo").token,
										paypwd:this.data.password,
										old_pwd:this.data.oldPw,
										confirm_pwd:this.data.surePws,
									};
									this._$InitRequest.request("MemberInfo/editpaypwd", params).then(res => {
										uni.showToast({title:res.mess,icon:"none"})
										if( res.status == 200 ){
											setTimeout(function(){
												uni.switchTab({
													url:"/pages/tabbar/mine"
												})
											},1500)
										}
									},error=>{})
								}
							}
						}
					}
				}
			}
		}
	}
</script>
<style lang="scss" scoped>
/deep/ .uni-input-input {font-size:32upx}
/deep/ .uni-radio-input-checked{background-color:rgb(110,43,34) !important;border:2upx solid white !important}
.content .html{
  ::v-deep {
    img {
      width: 100%;
    }
  }
}
</style>